package cn.lovelycatv.custom.GUI;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.HashMap;
import java.util.Map;

public class SynthesisGUI {

    private static final ItemStack GREEN_GLASS = new ItemStack(Material.STAINED_GLASS_PANE,1,(short) 5);
    private static final ItemStack ORANGE_GLASS = new ItemStack(Material.STAINED_GLASS_PANE,1,(short) 1);
    private static final ItemStack PURPLE_GLASS = new ItemStack(Material.STAINED_GLASS_PANE,1,(short) 2);
    private static final ItemStack ITEM_AIR = new ItemStack(Material.AIR,1);

    private static Map<Integer, ItemStack> synthesisGUIItems = new HashMap<>();

    private static final int[] BORDER = {2,3,4,5,6,11,20,29,38,15,24,33,42,39,40,41};
    private static final int CONFIRM = 26;
    private static final int DISMISS = 44;
    private static final int RESULT = 35;
    private static final int[] WORKPLACE = {12,13,14,21,22,23,30,31,32};
    private static final int[] AIR = {0,1,9,10,18,19,27,28,36,37,45,46,47,48,49,50,51,52,53,7,8,16,17,25,34,43};

    public static int[] getAir() {
        return AIR;
    }

    public static int getResult() {
        return RESULT;
    }

    private static Inventory getInventoryGUI(String title, int size) {
        return Bukkit.createInventory(null, size, title);
    }

    public static Inventory getSynthesisGUI(String title) {
        Inventory inventory = getInventoryGUI(title,6 * 9);
        return make(inventory);
    }

    private static Inventory make(Inventory inventory) {
        for (int i : BORDER) {
            ItemMeta itemMeta = GREEN_GLASS.getItemMeta();
            itemMeta.setDisplayName("§f分割线");
            GREEN_GLASS.setItemMeta(itemMeta);
            inventory.setItem(i,GREEN_GLASS);
        }
        for (int i : AIR) {
            inventory.setItem(i,ITEM_AIR);
        }
        ItemMeta CONFIRMitemMeta = GREEN_GLASS.getItemMeta();
        CONFIRMitemMeta.setDisplayName("§6合成");
        ORANGE_GLASS.setItemMeta(CONFIRMitemMeta);

        ItemMeta DISMISSitemMeta = GREEN_GLASS.getItemMeta();
        DISMISSitemMeta.setDisplayName("§b退出合成");
        PURPLE_GLASS.setItemMeta(DISMISSitemMeta);

        inventory.setItem(CONFIRM, ORANGE_GLASS);
        inventory.setItem(DISMISS, PURPLE_GLASS);
        return inventory;
    }

    public static void addItemIn(int solt,ItemStack itemStack) {
        synthesisGUIItems.put(solt,itemStack);
    }

    public static int getConfirm() {
        return CONFIRM;
    }

    public static int getDismiss() {
        return DISMISS;
    }

    public static int[] getWorkPlace() {
        return WORKPLACE;
    }

    public static int[] getWorkPlaceTop() {
        return new int[]{WORKPLACE[0], WORKPLACE[1], WORKPLACE[2]};
    }

    public static int[] getWorkPlaceCenter() {
        return new int[]{WORKPLACE[3], WORKPLACE[4], WORKPLACE[5]};
    }

    public static int[] getWorkPlaceBottom() {
        return new int[]{WORKPLACE[6], WORKPLACE[7], WORKPLACE[8]};
    }

    public static int getTop() {
        return getWorkPlaceTop()[1];
    }

    public static int getBottom() {
        return getWorkPlaceBottom()[1];
    }

    public static int getLeft() {
        return getWorkPlaceCenter()[0];
    }

    public static int getCenter() {
        return getWorkPlaceCenter()[1];
    }

    public static int getRight() {
        return getWorkPlaceCenter()[2];
    }

    public static int getTopLeft() {
        return getWorkPlaceTop()[0];
    }

    public static int getTopRight() {
        return getWorkPlaceTop()[1];
    }

    public static int getBottomLeft() {
        return getWorkPlaceBottom()[0];
    }

    public static int getBottomRight() {
        return getWorkPlaceBottom()[1];
    }

}
